#pragma once
#include <xmmintrin.h>
#include "vector3.h"
#include "quaternion.h"

namespace krryn{
namespace animation{
	class skeleton{
	public:
		static const unsigned int g_InvalidParent = -1;

		skeleton(unsigned int a_NumJoints);
		~skeleton();

		unsigned int num_joints() const;

		void set_joint_parent(unsigned int a_Idx, unsigned int a_Parent);
		void set_joint_position(unsigned int a_Idx, math::vector3f a_Position);
		void set_joint_rotation(unsigned int a_Idx, math::quaternionf a_Rotation);

		unsigned int get_joint_parent(unsigned int a_Idx);
		math::vector3f get_joint_position(unsigned int a_Idx);
		math::quaternionf get_joint_rotation(unsigned int a_Idx);

		static void interpolate(skeleton *a_Result, skeleton *a_First, skeleton *a_Second, float a_Alpha);
	private:
		// Round the number of joints up to the next simd register width (eg. 4 in case of sse / altivec)
		unsigned int num_joints_rounded() const;

		unsigned int m_NumJoints;
		unsigned int *m_Parents;

		// Bone positions
		__m128 *m_X;
		__m128 *m_Y;
		__m128 *m_Z;

		// Bone rotations as a quaternion
		__m128 *m_RX;
		__m128 *m_RY;
		__m128 *m_RZ;
		__m128 *m_RW;
	};
}
}